package com.xjrsoft.common.utils;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.extra.mail.MailAccount;
import com.xjrsoft.config.DingtalkConfig;
import com.xjrsoft.config.WechatEnterpriseConfig;
import com.xjrsoft.config.XjrSmsConfig;
import com.xjrsoft.module.system.model.DingtalkConfigModel;
import com.xjrsoft.module.system.model.EmailConfigModel;
import com.xjrsoft.module.system.model.MessageConfigModel;
import com.xjrsoft.module.system.model.WechatEnterpriseConfigModel;
import lombok.extern.slf4j.Slf4j;

/**
 * @Author: tzx
 * @Date: 2024/1/30 15:07
 */
@Slf4j
public class SystemConfigUtil {

    /**
     * 构建短信配置
     * @param messageConfigModel
     * @return
     */
    public static XjrSmsConfig createSmsConfig(MessageConfigModel messageConfigModel){
        log.info("------------- smsConfig init---------------");
        XjrSmsConfig smsConfig = new XjrSmsConfig();
        smsConfig.setPlatform(messageConfigModel.getCloudType());
        smsConfig.setLimitTime(messageConfigModel.getLimitTime());
        smsConfig.setLimitTime(messageConfigModel.getLimitCount());
        smsConfig.setCaptchaSender(messageConfigModel.getCaptchaSender());
        smsConfig.setCaptchaTemplateId(messageConfigModel.getCaptchaTemplateId());
        smsConfig.setNotifySender(messageConfigModel.getNotifySender());
        smsConfig.setNotifyTemplateId(messageConfigModel.getNotifyTemplateId());
        smsConfig.setCirculatedSender(messageConfigModel.getCirculatedSender());
        smsConfig.setCirculatedTemplateId(messageConfigModel.getCirculatedTemplateId());
        smsConfig.setTimeoutSender(messageConfigModel.getTimeoutSender());
        smsConfig.setTimeoutTemplateId(messageConfigModel.getTimeoutTemplateId());
        smsConfig.setMessageSendSender(messageConfigModel.getMessageSendSender());
        smsConfig.setMessageSendTemplateId(messageConfigModel.getMessageSendTemplateId());
        return  smsConfig;
    }

    /**
     * 构建企业微信配置
     * @param wechatEnterpriseConfigModel
     * @return
     */
    public static WechatEnterpriseConfig createWechatEnterpriseConfig(WechatEnterpriseConfigModel wechatEnterpriseConfigModel){
        log.info("------------wechatEnterpriseConfig init---------------");
        WechatEnterpriseConfig wechatEnterpriseConfig = new WechatEnterpriseConfig();
        wechatEnterpriseConfig.setAgentid(wechatEnterpriseConfigModel.getAgentId());
        wechatEnterpriseConfig.setAppKey(wechatEnterpriseConfigModel.getAppKey());
        wechatEnterpriseConfig.setAppSecret(wechatEnterpriseConfigModel.getAppSecret());
        wechatEnterpriseConfig.setRedirectUri(wechatEnterpriseConfigModel.getRedirectUri());
        return  wechatEnterpriseConfig;
    }

    /**
     * 构建钉钉配置
     * @param dingtalkConfigModel
     * @return
     */
    public static DingtalkConfig createDingtalkConfig(DingtalkConfigModel dingtalkConfigModel){
        log.info("------------wechatDingtalk Config init---------------");
        DingtalkConfig dingtalkConfig = new DingtalkConfig();
        dingtalkConfig.setAgentid(dingtalkConfigModel.getAgentId());
        dingtalkConfig.setAppKey(dingtalkConfigModel.getAppKey());
        dingtalkConfig.setAppSecret(dingtalkConfigModel.getAppSecret());
        dingtalkConfig.setRedirectUri(dingtalkConfigModel.getRedirectUri());
        return  dingtalkConfig;
    }

    /**
     * 构建邮件配置
     * @param emailConfigModel
     * @return
     */
    public static MailAccount createMailAccount(EmailConfigModel emailConfigModel){
        log.info("------------mail account config init---------------");
        MailAccount account = new MailAccount();
        account.setHost(emailConfigModel.getHost());
        account.setPort(emailConfigModel.getPort());
        if (ObjectUtil.isNotEmpty(emailConfigModel.getIsAuth())){
            account.setAuth(emailConfigModel.getIsAuth());
        }
        account.setFrom(emailConfigModel.getSender());
        account.setUser(emailConfigModel.getUserName());
        account.setPass(emailConfigModel.getPassword());
        return account;
    }
}
